package com.star.book.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.google.common.collect.Maps;
import com.star.book.entity.BookType;
import com.star.book.mapper.BookTypeMapper;
import com.star.book.service.IBookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr Kong
 * @since 2020-10-03
 */
@Service
public class BookTypeServiceImpl extends ServiceImpl<BookTypeMapper, BookType> implements IBookTypeService {
    @Autowired
    private IBookTypeService bookTypeService;
    @Override
    public List<BookType> findByPage(Integer id) {
        return baseMapper.findByPage(id);
    }

    @Override
    public Map<String, Object> bookTypeMap(Integer id) {
        Map<String, Object> bookTypeMap = Maps.newHashMap();
        List<BookType> list = bookTypeService.list();
        int bookTypeTotalCount = list.size();
        Integer page ;
        if(bookTypeTotalCount == 0 || bookTypeTotalCount < 0){
            page = 0;
        }else{
            page = bookTypeTotalCount / 10;
            if(bookTypeTotalCount % 10 > 0){
                page=page+1;
            }
        }
        bookTypeMap.put("page",page);
        List<BookType> byPage = baseMapper.findByPage(id);
        bookTypeMap.put("bookTypeByPage",byPage);
        return bookTypeMap;
    }
}
